package com.fancy.learncenter.ui.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.ui.activity.base.BaseActivity;
import com.fancy.learncenter.ui.adapter.FragPagerAdapter;
import com.fancy.learncenter.ui.fragment.CartoonExpandReleaseListenFragment;
import com.fancy.learncenter.ui.fragment.CartoonLocalListenFragment;
import com.fancy.learncenter.ui.fragment.CartoonReleaseListenFragment;
import com.fancy.learncenter.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

//已补发的拓展
public class CartoonExpandReleaseLocalActivity extends BaseActivity {

    public static String FILE_PATH_KEY = "FILE_PATH_KEY";
    String fileResPath;

    @Bind(R.id.view_pager)
    ViewPager viewPager;
    @Bind(R.id.top_img)
    ImageView topImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCartoonContentView(R.layout.activity_cartoon_expand_release_local, BaseActivity.Status.STATUS);
        ButterKnife.bind(this);

        fileResPath = getIntent().getStringExtra(FILE_PATH_KEY);
        LogUtil.MyLog("CartoonMyListenAndSpeakActivity", "====fileResPath=====" + fileResPath);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new CartoonExpandReleaseListenFragment());
        fragments.add(CartoonLocalListenFragment.newInstance(fileResPath));

        List titles = new ArrayList();
        titles.add("已发布的音频");
        titles.add("本地音频");
        FragPagerAdapter mFragmentAdapteradapter =
                new FragPagerAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        viewPager.setAdapter(mFragmentAdapteradapter);

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    topImg.setImageResource(R.mipmap.cartoon_expand_release);
                } else if (position == 1) {
                    topImg.setImageResource(R.mipmap.cartoon_expand_local);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }
}
